package com.soa.ws2http.controller;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.soa.ws2http.service.Webservice2HttpService;
import com.soa.ws2http.util.CodeMsg;

@RestController
@RequestMapping
public class Webservice2HttpController {
	@Autowired
	Webservice2HttpService webservice2HttpService;

	@ResponseBody
	@RequestMapping("/{resource}")
	public Object ws2http(@PathVariable String resource, HttpServletRequest request) {
		Map<String, String> paramMap = new HashMap<String, String>();
		Enumeration<String> enu = request.getParameterNames();
		String method="";
		while (enu.hasMoreElements()) {
			String paraName = (String) enu.nextElement();
			paramMap.put(paraName, request.getParameter(paraName));
			if("method".equals(paraName)){
				method=request.getParameter(paraName);
			}
		}
		CodeMsg codeMsg = webservice2HttpService.search(resource,method, paramMap);
		
		return codeMsg.getResponse();
	}
}
